// 公共方法的封装
import {requestUrl} from '../config/env'
let baseUrl = requestUrl();
// 提示语
const showToast = (message) => {
  uni.showToast({
      title:message,
      icon:'none'
    })
}
// 复制
const setClipboardData = (data) =>{
  uni.setClipboardData({
    data:data,
    success:function(){
     uni.showToast({
       title:'复制成功'
     })
    }
  })
}

// 上传图片
const uploadFile = (filePath) =>{
  return new Promise((resolve,reject) =>{
    const token = uni.getStorageSync('token');
    const url = `${baseUrl}/api/common/imageUpload?token=${token}`;
    uni.uploadFile({
      url:url,
      filePath:filePath,
      name:'file',
      success:(res) => {
       resolve(res) 
      },
      fail:(error) =>{
        reject(error)
      }
    })
  })
}

// 列表的封装
const listMethod = (items , urls) =>{
  if(urls !== ''){
    let encodeUrls = encodeURIComponent(urls)
    uni.navigateTo({
      url:'/pages/webView/webView?urls=' + encodeUrls
    })
  }else {
    items()
  }
}


export default{
  showToast,
  setClipboardData,
  uploadFile,
  listMethod,
}